﻿<%@ Page Title="Edit Page Content" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="EditContent.aspx.cs" Inherits="ColorApplication.color.EditContent" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor"
    TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript" src="../scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="../FileManager/js/AjaxToolKitManager.js"></script>
    <script type="text/javascript">
        //        var Editor1 = '#MainContent_ContentDetailsView_Editor1';
        //        var Editor1CountLimit = 500;
        //        var Editor1InfoArea = '#Info';
        //        $(document).ready(function () {
        //            TrackCharacterCount(Editor1, Editor1CountLimit);
        //        });

        //        function TrackCharacterCount(ctl, limit) {
        //            var editor = $(ctl).contents().find('iframe').eq(2);
        //            $(editor).load(function () {
        //                var txt = $(this).contents().find('body').text();

        //                $(this).contents().keyup(function () {
        //                    //If the keypress fail and allow write more text that required, this event will remove it
        //                    var txt = $(this).contents().find('body').text();
        //                    if (txt.length > limit) {
        //                        $(info).html(txt.length).css("color", "red");
        //                        $(this).contents().find('body').empty();
        //                        $(this).contents().find('body').text(txt.substring(0, limit));
        //                    }
        //                    else {
        //                        $(info).html(txt.length).css("color", "black");
        //                    }
        //                });
        //            });
        //        }


    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="adminContent">
        <h2>Edit content</h2>
<%--        <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
            <ProgressTemplate>
                <div id="modalPage" runat="server" class="modalPage">
                    <div class="modalBackground">
                    </div>
                    <div class="modalContainer">
                        <div class="modal">
                            <table>
                                <tr>
                                    <td align="center">
                                        <div style="background-color: White; border-radius: 5px; color: black; height: 47px;
                                            padding-top: 5px;">
                                            Please Wait...
                                        <br />
                                            <img src="../Images/preloader.gif" />
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>--%>
<%--        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>--%>
                <asp:Label ID="ErrorLabel" runat="server" CssClass="failureNotification"></asp:Label>
                <asp:Label ID="SuccesLabel" runat="server" CssClass="successNotification"></asp:Label>
                <asp:DetailsView ID="ContentDetailsView" runat="server" Height="50px" Width="100%"
                    AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="ContentDetailsViewSqlDataSource"
                    DefaultMode="Insert" OnItemInserted="ContentDetailsView_ItemInserted" OnItemUpdated="ContentDetailsView_ItemUpdated"
                    OnItemInserting="ContentDetailsView_ItemInserting" OnItemUpdating="ContentDetailsView_ItemUpdating">
                    <Fields>
                        <asp:TemplateField HeaderText="Page Name" SortExpression="PageName">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PageName") %>' MaxLength="50"></asp:TextBox>
                                <asp:RequiredFieldValidator ErrorMessage="Page Name is required." ControlToValidate="TextBox1"
                                    CssClass="failureNotification" runat="server" Display="Dynamic" />
                                <asp:Label Text="eg: &quot;AboutUs&quot;, &quot;ContactUs&quot;" runat="server" />
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PageName") %>' MaxLength="50"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ErrorMessage="Page Name is required."
                                    ControlToValidate="TextBox1" Display="Dynamic" CssClass="failureNotification"
                                    runat="server" />
                                <asp:Label ID="Label3" Text="eg: &quot;AboutUs&quot;, &quot;ContactUs&quot;" runat="server" />
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("PageName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Text" SortExpression="Text">
                            <EditItemTemplate>
                                <asp:Editor ID="Editor1" runat="server" Content='<%# Bind("Text") %>' BackColor="White"
                                    ForeColor="Black" Height="500px" />
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ErrorMessage="Text is required."
                                    ControlToValidate="Editor1"
                                    runat="server" Display="Dynamic" CssClass="failureNotification" />
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:Editor ID="Editor1" runat="server" Content='<%# Bind("Text") %>' BackColor="White"
                                    ForeColor="Black" Height="500px" />
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ErrorMessage="Text is required."
                                    ControlToValidate="Editor1"
                                    runat="server" Display="Dynamic" CssClass="failureNotification" />
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("Text") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ShowEditButton="true" ShowInsertButton="true" />
                    </Fields>
                </asp:DetailsView>
                <asp:SqlDataSource ID="ContentDetailsViewSqlDataSource" runat="server" CancelSelectOnNullParameter="False"
                    ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" InsertCommand="InsertContent"
                    InsertCommandType="StoredProcedure" SelectCommand="GetContent" SelectCommandType="StoredProcedure"
                    UpdateCommand="UpdateContent" UpdateCommandType="StoredProcedure">
                    <InsertParameters>
                        <asp:Parameter Name="PageName" Type="String" />
                        <asp:Parameter Name="Text" Type="String" />
                    </InsertParameters>
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ContentGridView" Name="Id" PropertyName="SelectedValue"
                            Type="Int32" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="Id" Type="Int32" />
                        <asp:Parameter Name="PageName" Type="String" />
                        <asp:Parameter Name="Text" Type="String" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <br />
                <br />
                <table>
                    <tr>
                        <td>Search By Page Name : </td>
                        <td>
                            <asp:TextBox ID="SearchPageNameTextBox" AutoPostBack="true" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                </table>
                <br />
                <asp:GridView ID="ContentGridView" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
                    DataSourceID="ContentGridSqlDataSource" Width="100%" OnRowDeleting="ContentGridView_RowDeleting"
                    OnSelectedIndexChanged="ContentGridView_SelectedIndexChanged" AllowSorting="True">
                    <Columns>
                        <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True"
                            SortExpression="Id" Visible="False" />
                        <asp:BoundField DataField="PageName" HeaderText="Page Name" SortExpression="PageName" />
                        <asp:CommandField SelectText="Edit" ShowSelectButton="True" />
                        <asp:TemplateField ShowHeader="False">
                            <ItemTemplate>
                                <asp:LinkButton ID="DeleteLinkButton" runat="server" CausesValidation="False" CommandName="Delete"
                                    Text="Delete"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="ContentGridSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                    DeleteCommand="DeleteContent" DeleteCommandType="StoredProcedure" SelectCommand="GetContentSearchByPageName"
                    SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="False">
                    <DeleteParameters>
                        <asp:Parameter Name="Id" Type="Int32" />
                    </DeleteParameters>
                    <SelectParameters>
                        <asp:ControlParameter ControlID="SearchPageNameTextBox" PropertyName="Text" Name="PageName"
                            Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <script type="text/javascript" language="javascript">

                    $(".ajax__htmleditor_editor_toptoolbar").each(function (index) {
                        $(this).html($(this).html() + "<img title='Insert Image' onclick=showImgManager('" + index + "') src='../FileManager/icons/ed_upload_image_n.gif' class='ajax__htmleditor_toolbar_button' /><img title='External URL' onclick=showFileManager('" + index + "') src='../FileManager/icons/inserturl.gif' class='ajax__htmleditor_toolbar_button' /><div style='display:none;float:left;width:100%;padding-top:5px;' id='divImgManager" + index + "'></div>");

                    });
                    function openFileManager(index) {

                        window.open("../FileManager/FileManagerForEditor.aspx?sessionid=<%= Session.SessionID %>&input=" + index, "myWindow", "status = 1, height = 650, width = 950, resizable = 0")
                    }
                </script>
<%--            </ContentTemplate>
        </asp:UpdatePanel>--%>
    </div>

</asp:Content>
